package com.test.mq.consumer;

import com.lee.message.core.annotation.Idempotent;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@Component
@RocketMQMessageListener(topic = "queue_test_topic", selectorExpression = "*", consumerGroup = "queue_group_test")
@Idempotent(type = "test", storeTime = 5, storeTimeUnit = TimeUnit.SECONDS)
public class RocketMqListener implements RocketMQListener<MessageExt> {

    AtomicInteger ai = new AtomicInteger();

    @Override
    @Idempotent(type = "test", storeTime = 10, storeTimeUnit = TimeUnit.SECONDS)
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        String msg = new String(body);
        log.info("接收到消息：" + msg + ai.incrementAndGet());
    }

}